import 'package:flutter/material.dart';

//加载进度条组件
class LoadingContainer extends StatelessWidget {
  final Widget child;
  final bool isLoading;
  final bool cover;

  const LoadingContainer({super.key,
    required this.isLoading,
    this.cover = false,
    required this.child});

  @override
  Widget build(BuildContext context) {
    return !cover
        ? !isLoading
        ? child
        : _loadingView
        : Stack(
      children: <Widget>[
        child,
        if (isLoading) _loadingView,
      ].whereType<Widget>().toList(),
    );
  }

  Widget get _loadingView {
    return Center(
      child: CircularProgressIndicator(),
    );
  }
}
